<?xml
	version="1.0"
	encoding="UTF-8" ?>
<!DOCTYPE html>

<html
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"      
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
    
    <f:metadata>
    	<f:event
    		type="preRenderView"
    		listener="#{debugPage.checkDebugEnabled}" />
    </f:metadata>
    
    <f:view>        
	    <h:head>
	    	<title>CDI Debug Page</title>
	    	
	    	<style type="text/css">
	    		body, td {
	    			font-family: Tahoma, Verdana, Arial, sans-serif;
	    			font-size: 12px;
	    		}
	    	
	    		h1, h2, h3 {
	    			display: inline;
	    			margin: 0;
	    			padding: 0;
	    		}
	    		
	    		.propertyLabel {
	    			background-color: LightGray;
	    		}
	    		
	    		.null {
	    			font-style: italic;
	    		}
	    		
	    		.error {
	    			color: red;
	    		}
	    		
	    		.wrap {
	    			white-space: normal;
	    		}
	    	</style>
	    	
	    	<h:outputScript name="jsf.js" library="javax.faces"/> 
	    </h:head>
	    
	    <h:body>	    
	    	<h1>CDI Debug Page</h1>
	    	
	    	<br />
	    	
	    	<h:form
	    		id="sessionsForm">
	    		
	    		<h:panelGroup
	    			rendered="#{empty debugObserver.sessionIds}">
	    			<h2>No active sessions</h2>
	    		</h:panelGroup>
	    		
	    		<br />
	    		
		    	<p:dataTable
		    		rendered="#{not empty debugObserver.sessionIds}"
		    		value="#{debugObserver.sessionIds}"
		    		var="_sessionId">
		    		<ui:param
		    			name="_session"
		    			value="#{debugObserver.getSession(_sessionId)}" />
		    		
		    		<f:facet name="header">
		    			<h2>Active Sessions</h2>
		    		</f:facet>
		    		<p:column>
		    			<f:facet name="header">
			    			Session ID
			    		</f:facet>
			    		#{_sessionId}
		    		</p:column>
		    		
		    		<p:column>
		    			<f:facet name="header">
			    			Last Requested View
			    		</f:facet>
			    		#{_session.lastView}
		    		</p:column>
		    		
		    		<p:column>
		    			<f:facet name="header">
			    			Actions
			    		</f:facet>
			    		<p:commandLink
			    			ajax="false"
			    			value="Inspect"
			    			action="#{debugPage.viewSession(_session)}" />
			    		-
			    		<p:commandLink
			    			ajax="false"
			    			value="Close"
			    			action="#{debugPage.invalidateSession(_session)}"/>
		    		</p:column>
		    	</p:dataTable>
		    </h:form>
		    
		    <p:messages autoUpdate="true"/>
	    	
	    	<p>Please note contexts are only updated when the session's "Inspect" link is clicked.</p>
	    	<h3>Active Contexts:</h3>
	    	
	    	<h:form
	    		id="scopesForm"
	    		rendered="#{not empty debugPage.viewingSession}">
		    	<ui:repeat
		    		value="#{debugObserver.scopeNames}"
		    		var="_scopeName">
		    		<p:panel
		    			rendered="#{not empty debugPage.viewingSession.getBeans(_scopeName)}"
		    			toggleable="true"
		    			collapsed="true"
		    			toggleSpeed="0">
		    			<f:facet name="header">
		    				#{_scopeName}
		    			</f:facet>	    		
			    		<ui:repeat
			    			value="#{debugPage.viewingSession.getBeans(_scopeName)}"
			    			var="_bean">
			    			<p:commandLink
			    				action="#{debugPage.viewBean(_bean)}"
			    				update=":viewBeanPanel"
			    				value="#{_bean.className}" /><br />
			    		</ui:repeat>
		    		</p:panel>
		    	</ui:repeat>
	    	</h:form>
	    	
	    	<br />
	    	
	    	<h:panelGroup
	    		id="viewBeanPanel">
		    	<h:panelGroup
		    		rendered="#{not empty debugPage.viewingBean}">
		    		<h3>Inspect bean</h3>
		    		
		    		<p:dataTable
		    			columnClasses="propertyLabel"
		    			value="#{debugPage.viewingBean.propertyNames}"
		    			var="_propertyName">
		    			<f:facet name="header">
		    				<h3>#{debugPage.viewingBean.className}</h3>
		    			</f:facet>
		    			
		    			<ui:param
		    				name="_property"
		    				value="#{debugPage.viewingBean.getPropertyValue(_propertyName)}" />
		    			
		    			<p:column headerText="Type">
		    				<strong>#{debugPage.viewingBean.getPropertyType(_propertyName)}</strong>
		    			</p:column>
		    			
		    			<p:column headerText="Name">
		    				<strong>#{_propertyName}</strong>
		    			</p:column>
		    			
		    			<p:column headerText="Value">
		    				<div class="wrap">
		    					<p:commandLink
		    						rendered="#{debugPage.viewingBean.isInspectable(_propertyName)}"
		    						action="#{debugPage.inspectBeanProperty(_propertyName)}"
		    						update=":viewBeanPanel">
		    						<h:outputText
		    							escape="false"
		    							value="#{_property}" />
		    					</p:commandLink>
		    					
		    					<h:outputText
		    						rendered="#{not debugPage.viewingBean.isInspectable(_propertyName)}"
		    						escape="false"
		    						value="#{_property}"/>
		    				</div>
		    			</p:column>
		    		</p:dataTable>
		    		
		    		<p><strong>toString() output:</strong><br />
		    			#{debugPage.viewingBean}
		    		</p>
		    		
		    		<p:commandLink
   						rendered="#{not empty debugPage.viewingBean.parent}"
   						value="Back to parent: #{debugPage.viewingBean.parent.className}"
   						action="#{debugPage.viewBean(debugPage.viewingBean.parent)}"
   						update=":viewBeanPanel" />
		    	</h:panelGroup>
	    	</h:panelGroup>
	    </h:body>	 
    </f:view>
</html>